
package horde.interfaces;

import horde.patterns.Msg;
import horde.patterns.master.MasterAgent;
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;

/**
 * Interface to access some of the master agent methods
 * @author Arturo Mazon
 * @author Andres Picazo
 */
public class Requests extends UnicastRemoteObject implements MasterItf {
    public static final String TRACE_INFO = "INFO";
    public static final String TRACE_DEBUG = "DEBUG";
    public static final String TRACE_ERROR = "ERROR";
    private MasterAgent master;
    /**
     * Constructor
     * @param M The Master Agent
     */
    public Requests (MasterAgent M) throws RemoteException {        
            master = M;
    }

    public static Requests createRequests (MasterAgent M) {
        try {
            Requests r = new Requests (M);
            return r;
        } catch (Exception e) {            
            return null;
        }
    }

    /**
     * Send a message msg. Msg is a package that includes the necessary
     * information to send the message to the target required with the
     * options needed.
     * 
     * @param msg Message to be sent
     * @return True if the message was delivered, false otherwise
     * @deprecated
     */
    @Deprecated
    public boolean sendMessage (Msg msg) {
        return master.sendMessage(msg);
    }

    /**
     * Gets a shared resource from the directory, throught the master (can be done from the directory)
     * @param id Id representing the resource to be retrieved
     * @return Instance of the resource, null if none has been found
     */
    public Object getSharedResource (String id) {
        return master.getSharedResource(id);
    }

    /**
     * Posts a new message, the master will deliver it.
     * @param msg Message to be posted
     * @return true if the message was delivered, false otherwise
     */
    public boolean post (Msg msg) {
        return master.post(msg);
    }

    /**
     * Requests the master to stop all the agents.
     * Note: This will probably stop the application, use with caution.
     */
    public void halt () {
        master.stopAgents();
    }

    @Deprecated
    public void reportStatus (String newStatus) {

    }
   
}
